home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Source ƒ / sky source ƒ / MAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-16  |  4.9 KB  |  347 lines

  1. #include "sky.h"
  2. #include <stdio.h>
  3.  
  4. main(argc,argv)
  5. int argc;
  6. char *argv[];
  7. {
  8.  
  9.     pi = 3.1415926535897932;
  10.     radian = pi/180.;
  11.     radsec = radian/3600.;
  12.     args(argc,argv);
  13.     init();
  14.  
  15.  
  16.     for(;;){
  17.         day = readate();
  18.         printf("Date: ");
  19.         pdate(day);
  20.         printf("\n");
  21.         printf("Time: ");
  22.         ptime(day);
  23.         printf("\n");
  24.         if(day < 0.)
  25.             printf("Julian date %.4f\n", day+2415020.);
  26.         setime(day);
  27.  
  28.     if(flags&TOPO){
  29.         printf("               rt. ascens.      decl.       az.     elev.    mag.\n");
  30.     }
  31.  
  32.         if((flags&HELIO)==0){
  33.             lambda = 0.;
  34.             beta = 0.;
  35.             rad = 0.;
  36.             ldot = 0.;
  37.             rdot = 0.;
  38.             bdot = 0.;
  39.         }else{
  40.             object = "earth       ";
  41.         }
  42.         helio();
  43.  
  44. /*
  45.  *    Shadow computation for lunar eclipse.
  46.  */
  47.  
  48.         rps = georad;
  49.         shra = alpha + 180.*radian;
  50.         shdecl = -delta;
  51.  
  52.         geo();
  53.  
  54. /*
  55.  *    Computation for solar eclipse.
  56.  */
  57.  
  58.         sunra = ra;
  59.         sundec = decl2;
  60.         sunsd = semi2;
  61.  
  62.         output();
  63.  
  64.         moon();
  65.         output();
  66.  
  67.         merc();
  68.         output();
  69.  
  70.         venus();
  71.         output();
  72.  
  73.         mars();
  74.         output();
  75.  
  76.         jup();
  77.         output();
  78.  
  79.         sat();
  80.         output();
  81.  
  82.         halley();  /* added for 1986 rhm/enm */
  83.         output();
  84.  
  85.         if((flags&NOSTAR)==0){
  86.             stars();
  87.         }
  88.  
  89.     }
  90.  
  91. }
  92.  
  93. args(argc,argv)
  94. int argc;
  95. char *argv[];
  96. {
  97.     register char *p, *q;
  98.  
  99.     p = "";
  100.     if(argc>1)
  101.         p = argv[1];
  102.     while(*p)
  103.     switch(*p++){
  104.  
  105. /*
  106.  *    Meanings of options.
  107.  *
  108.  *    APPARENT: Catalogue apparent place omits
  109.  *    short period terms of nutation for direct
  110.  *    comparison with "Apparent Places of
  111.  *    Fundamental Stars".
  112.  *
  113.  *    OCCULT: Changes the semidiameters of the
  114.  *    sun and moon, and moves the moon slightly.
  115.  *
  116.  *    LATUD: prompts for longitude, latitude and elevation.
  117.  *
  118.  *    MEAN: omits all nutation, for direct comparison
  119.  *    with star catalogs. Also omits the E-terms of nutation.
  120.  *
  121.  *    NOSTAR: Solar system only.
  122.  *
  123.  *    STCATL: Prompts for name of file containing star catalog.
  124.  *
  125.  *    XYZ: Prints x,y,z, coordinates vice angles.
  126.  *
  127.  *    GEO: Reports apparent geocentric place.
  128.  *
  129.  *    HELIO: Reports heliocentric place.
  130.  *
  131.  *    TOPO: Reports topocentric place.Default location
  132.  *    is the hollyhock in Morris's back yard.
  133.  *
  134.  *    ECLIPTIC: Reports places in ecliptic vs. equatorial coords.
  135.  *
  136.  *    KITCH: Input times are interpreted as local time
  137.  *    vs. Greenwich time (but still E.T.)
  138.  */
  139.  
  140.     case 'a':
  141.         flags |= APPARENT;
  142.         continue;
  143.  
  144.     case 'e':
  145.         flags |= OCCULT;
  146.         continue;
  147.  
  148.     case 'l':
  149.         flags |= LATUD;
  150.         continue;
  151.  
  152.     case 'm':
  153.         flags |= MEAN;
  154.         continue;
  155.  
  156.     case 'p':
  157.         flags |= NOSTAR;
  158.         continue;
  159.  
  160.     case 's':
  161.         flags |= STCATL;
  162.         continue;
  163.     case 'x':
  164.         flags |= XYZ;
  165.         continue;
  166.  
  167.     case 'g':
  168.         flags |= GEO;
  169.         continue;
  170.  
  171.     case 'h':
  172.         flags |= HELIO;
  173.         continue;
  174.  
  175.     case 'c':
  176.         flags |= ECLIPTIC;
  177.         continue;
  178.  
  179.     case '-':
  180.         continue;
  181.  
  182.     default:
  183.         printf("Unknown option '%c'\n",p[-1]);
  184.     }
  185.     if(!((flags&GEO)||(flags&HELIO))){
  186.         flags |= TOPO;
  187.     }
  188.  
  189. }
  190.  
  191. readlat()
  192. {
  193.     register i;
  194.     double ifa[3];
  195.  
  196.     printf("NLat(deg) WLong(deg) elev(meters)\n");
  197.     rline(stdin);
  198.     for(i=0; i<3; i++)
  199.         ifa[i] = atof(skip(i));
  200.     nlat = ifa[0] * radian;
  201.     wlong = ifa[1] * radian;
  202.     elev = ifa[2];
  203. }
  204.  
  205. readcat()
  206. {
  207.     char *gets();
  208.     char *p;
  209.  
  210.     printf("Enter name of star catalog: ");
  211.     p = startab;
  212.     gets(p);
  213. }
  214.  
  215. init()
  216. {
  217.  
  218.     register char *p, *q;
  219.  
  220.     wlong = (74.+32./60.)*radian;
  221.     nlat = (40.+40./60.)*radian;
  222.     elev = 0.;
  223.     if(flags & LATUD)
  224.         readlat();
  225.     prlat();
  226.     glat = nlat - (692.74*radsec)*sin(2.*nlat)
  227.          + (1.16*radsec)*sin(4.*nlat);
  228.     erad = .99832707 + .00167644*cos(2.*nlat)
  229.          - 0.352e-5*cos(4.*nlat)
  230.          + 0.001e-5*cos(6.*nlat)
  231.          + 0.1568e-6*elev;
  232.     q = "/u1/eugene/src/sky/startab";
  233.     for(p = startab; *p++ = *q++;)
  234.         ;
  235.     if(flags & STCATL)
  236.         readcat();
  237. /*
  238.     printf("%s\n", startab);
  239. */
  240. }
  241. rline(f)
  242. FILE *f;
  243. {
  244.     register char *p;
  245.     register c;
  246.  
  247.     p = line;
  248.     do {
  249.         c = getc(f);
  250.         if(c < 0)
  251.             return(1);
  252.         *p++ = c;
  253.     } while(c != '\n');
  254.     return(0);
  255. }
  256.  
  257. char*
  258. skip(n)
  259. {
  260.     register i;
  261.     register char *cp;
  262.  
  263.     cp = line;
  264.     for(i=0; i<n; i++) {
  265.         while(*cp == ' ' || *cp == '\t')
  266.             cp++;
  267.         while(*cp != '\n' && *cp != ' ' && *cp != '\t')
  268.             cp++;
  269.     }
  270.     while(*cp == ' ' || *cp == '\t')
  271.         cp++;
  272.     return(cp);
  273. }
  274. double
  275. readate()
  276. {
  277.     register i;
  278.     double ifa[5];
  279.  
  280.     printf("year mo da hr min\n");
  281.     if(rline(stdin) != 0)
  282.         exit(0);
  283.     for(i=0; i<5; i++)
  284.         ifa[i] = atof(skip(i));
  285.     return(convdate(ifa));
  286. }
  287.  
  288. double
  289. convdate(ifa)
  290. double ifa[];
  291. {
  292.     double y, d, temp;
  293.     register i;
  294.  
  295.     y = ifa[0];
  296.     i = ifa[1];
  297.     d = ifa[2];
  298.     temp = 0.;
  299.     if(d>28.){
  300.         temp = d - 28.;
  301.         d = 28.;
  302.     }
  303.     while(i < 1) {
  304.         i += 12;
  305.         y -= 1.;
  306.     }
  307.     while(i > 12) {
  308.         i -= 12;
  309.         y += 1.;
  310.     }
  311.     if(y < 0.)
  312.         y += 1.;
  313.     y += 4712.;
  314.     if(fmod(y, 4.) == 0 && i > 2)
  315.         d += 1.;
  316.     y = y*365. +
  317.         floor((y+3.)/4.) +
  318.         dmo[i-1] + d - 1.;
  319.     if(y > 2361232.)
  320.         y -= floor((y-1794167.)/36525.) -
  321.             floor((y-1721117.)/146100.);
  322.     y += ifa[3]/24. + ifa[4]/1440. - .5 + temp;
  323.     return(y-2415020.);
  324. }
  325. setime(day)
  326. double day;
  327. {
  328.  
  329.  
  330.     eday = day;
  331.     deltat = eday * .00167;
  332.     glong = wlong;
  333.     if(flags & OCCULT)
  334.         glong += 15.*deltat*radsec;
  335.     capt = eday/36525.;
  336.     capt2 = capt*capt;
  337.     capt3 = capt2*capt;
  338.     nutate();
  339.  
  340.     aberr();
  341.  
  342.     sun();
  343.     xms = rad*cos(beta)*cos(lambda);
  344.     yms = rad*cos(beta)*sin(lambda);
  345.     zms = rad*sin(beta);
  346. }
  347.